package com.newdjk.newdoctor.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import androidx.fragment.app.Fragment;

import com.newdjk.newdoctor.dialog.LoadDialog;
import com.newdjk.newdoctor.utils.LogUtils;

import butterknife.ButterKnife;


/**
 * Created by huhai on 2018-3-12.
 */

public abstract class BasicFragment extends Fragment implements View.OnClickListener {

    // 管理activity
    protected Context mContext;
    protected Activity mActivity;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(initViewResId(), container, false);
        ButterKnife.bind(this, view);
        mActivity = getActivity();
        mContext = getActivity();
        initView();
        initListener();
        initData();
        return view;
    }

    /**
     * 初始化界面
     */
    protected abstract int initViewResId();

    /**
     * 初始化界面
     */
    protected abstract void initView();

    /**
     * 初始化界面
     */
    protected abstract void initListener();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    /**
     * 点击事件
     *
     * @param view
     */
    protected abstract void otherViewClick(View view);

    /**
     * 点击的事件的统一的处理
     *
     * @param view
     */
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            default:
                otherViewClick(view);
                break;
        }
    }

    /**
     * @param str 日志的处理
     */
    protected void logE(String str) {
        LogUtils.e("" + this.getClass().getSimpleName(), str);
    }


    /**
     * 加载效果
     *
     * @param bool
     */
    public void loading(boolean bool) {
        if (bool) {
            LoadDialog.show(getContext());
        } else {
            LoadDialog.clear();
        }
    }
    /**
     * 加载效果
     *
     * @param bool
     */
    protected void loading(boolean bool, String content) {
        if (bool) {
            LoadDialog.show(getContext(), content);
        } else {
            LoadDialog.clear();
        }
    }






}
